home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_compiler.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  104 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import compiler
  5. import os
  6. import test.test_support as test
  7. import unittest
  8. from random import random
  9.  
  10. class CompilerTest(unittest.TestCase):
  11.     
  12.     def testCompileLibrary(self):
  13.         libdir = os.path.dirname(unittest.__file__)
  14.         testdir = os.path.dirname(test.test_support.__file__)
  15.         for dir in [
  16.             libdir,
  17.             testdir]:
  18.             for basename in os.listdir(dir):
  19.                 if not basename.endswith('.py'):
  20.                     continue
  21.                 
  22.                 if not TEST_ALL and random() < 0.97999999999999998:
  23.                     continue
  24.                 
  25.                 path = os.path.join(dir, basename)
  26.                 if test.test_support.verbose:
  27.                     print 'compiling', path
  28.                 
  29.                 f = open(path, 'U')
  30.                 buf = f.read()
  31.                 f.close()
  32.                 if 'badsyntax' in basename:
  33.                     self.assertRaises(SyntaxError, compiler.compile, buf, basename, 'exec')
  34.                     continue
  35.                 compiler.compile(buf, basename, 'exec')
  36.             
  37.         
  38.  
  39.     
  40.     def testLineNo(self):
  41.         filename = __file__
  42.         if filename.endswith('.pyc') or filename.endswith('.pyo'):
  43.             filename = filename[:-1]
  44.         
  45.         tree = compiler.parseFile(filename)
  46.         self.check_lineno(tree)
  47.  
  48.     
  49.     def check_lineno(self, node):
  50.         
  51.         try:
  52.             self._check_lineno(node)
  53.         except AssertionError:
  54.             print node.__class__, node.lineno
  55.             raise 
  56.  
  57.  
  58.     
  59.     def _check_lineno(self, node):
  60.         if node.__class__ not in NOLINENO:
  61.             self.assert_(isinstance(node.lineno, int), 'lineno=%s on %s' % (node.lineno, node.__class__))
  62.             self.assert_(node.lineno > 0, 'lineno=%s on %s' % (node.lineno, node.__class__))
  63.         
  64.         for child in node.getChildNodes():
  65.             self.check_lineno(child)
  66.         
  67.  
  68.  
  69. NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)
  70.  
  71. class Toto:
  72.     '''docstring'''
  73.     pass
  74.  
  75. (a, b) = (2, 3)
  76. (c, d) = (5, 6)
  77. l = [ (x, y) for x, y in zip(range(5), range(5, 10)) ]
  78. l[0]
  79. l[3:4]
  80.  
  81. try:
  82.     print yo
  83. except:
  84.     None if l else []
  85.     yo = 3
  86.  
  87. yo += 3
  88.  
  89. try:
  90.     a += b
  91. finally:
  92.     b = 0
  93.  
  94. from math import *
  95.  
  96. def test_main():
  97.     global TEST_ALL
  98.     TEST_ALL = test.test_support.is_resource_enabled('compiler')
  99.     test.test_support.run_unittest(CompilerTest)
  100.  
  101. if __name__ == '__main__':
  102.     test_main()
  103.  
  104.